Skip to content

fix(mcp-server): honour task ttl and test not-found after session close - #1671

Merged
smart-ssh-coordinator[bot] merged 2 commits into
developfrom
issue-1660-mcp-tasks-honour-ttl-test-not-found
Dec 4, 2026
Merged

smart-ssh-coordinator[bot] merged 2 commits into
developfrom
issue-1660-mcp-tasks-honour-ttl-test-not-found

Conversation

@smart-ssh-coder

Copy link
Copy Markdown
Contributor

Closes #1660

Summary

MCP task bookkeeping now honours the task's ttlMs (measured from creation, lazily on lookup and on registration; no timer). Tasks without ttl stay until the session closes. Spec 0028 §10a describes ttl and the Completed decision.

Acceptance Criteria

  • Short ttl → not-found, hook not called: met (extension.rs:test_task_expires_after_its_ttl_without_asking_the_extension)
  • Before ttl both reach the extension: met (same test, at ttl−1ms)
  • Expired entries removed on registration: met (extension.rs:test_registering_a_task_drops_expired_entries; no sweep without registration); no-ttl kept: test_task_without_ttl_is_kept
  • After session close not-found (-32602), extension not called: met (tests/tasks.rs:test_task_of_a_closed_session_is_not_found_and_the_extension_is_not_called)
  • Spec 0028 §10a covers ttl and Completed: met
  • Tests pass: met (cargo test -p mcp-server, clippy clean); CI below

Tests

Counter-proof: disabling the expiry check on lookup makes the ttl test fail.

Assumptions

Owner check on the client is unchanged. Timing uses tokio::time::Instant so tests run with paused time.

Spec

updated 0028

Threat model: no change – only forgets task ids earlier; owner check unchanged.

Follow-ups

None.

🤖 Generated with Claude Code

…se (#1660)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

@smart-ssh-reviewer smart-ssh-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review

Verdict: approved
Review level: elevated

Blocking

None.

Non-blocking

  • docs/specs/0028-mcp-server-integration.md §10a, Completed sentence: the example "(etwa weil es schon ohne Start fertig ist)" is vague. In the code, Completed arises when the outcome is Approved but no command handle was handed over: Approval::Other, the action id not yet known in the MCP backend, or no approval signal at all (tool_server.rs resolve_pending_decision). The main statement (approved, no access, carries the final result like the built-in tool) matches outcome_to_tool_result, so this is wording only.
  • Open PR #1672 also edits task_status/cancel_task in crates/mcp-server/src/extension.rs. Whichever PR merges second will need a textual merge. They don't conflict in substance.

Verified

  • files read: 2/2 logic files (crates/mcp-server/src/extension.rs, crates/mcp-server/tests/tasks.rs), complete diff, plus the spec and changelog fragment
  • counter-proof (executed): I disabled the expiry check in task_owner. test_task_expires_after_its_ttl_without_asking_the_extension failed and passed again after the restore. I removed the retain in answer_as_task. test_registering_a_task_drops_expired_entries failed and passed again after the restore. I removed the retain in notify_session_closed. tests/tasks.rs:test_task_of_a_closed_session_is_not_found_and_the_extension_is_not_called failed and passed again after the restore.
  • AC mapping (read):
    • AC1 → extension.rs:test_task_expires_after_its_ttl_without_asking_the_extension (at the ttl, get gives None and cancel gives false, hook count stays 2)
    • AC2 → same test at ttl − 1 ms (both reach the hook)
    • AC3 → test_registering_a_task_drops_expired_entries (count is 2, stays 2 with no registration, drops to 1 after a registration)
    • AC4 → tests/tasks.rs:test_task_of_a_closed_session_… (asserts -32602 for get and cancel on 2026-07-28, status_ctx unchanged, cancelled empty)
    • AC5 → spec §10a and §10 updated
    • tasks without a ttl: test_task_without_ttl_is_kept
  • edge cases (read):
    • ttl 0 → expires at once (>=), ok
    • ttlMs = u64::MAX → Duration::from_millis plus saturating_duration_since, nothing added, so no overflow; ok
    • re-registering an id whose entry expired → retain runs before the duplicate check, so the id is accepted; ok
    • duplicate of a live id → still rejected; ok
    • lookup of another client's expired id → entry removed and not-found returned, same answer as before; ok
    • lock never held across an await; ok
  • callers checked: answer_as_task (1 production call site, tool_server.rs:465), task_owner (2, both internal), notify_session_closed (app-shell/src/sessions.rs:95, behaviour unchanged) → ok
  • tests run locally: cargo test --locked -q -p mcp-server → 62 passed (executed). cargo clippy --locked -p mcp-server --all-targets -- -D warnings and cargo fmt --all --check were clean (executed).
  • CI: all checks green (gh pr checks 1671)
  • UI: not a UI change
  • data: not touched (in-memory map only)

Timing analysis

  • 2 test files analysed: no timing dependency found. The unit tests use start_paused = true with tokio::time::Instant in the code under test, so the boundary check is exact. The integration test closes the session directly, without sleeps or fixed ports.

Spec

  • visible behaviour changed: an MCP task becomes not-found once its ttlMs has elapsed. Tasks without a ttl stay until the session closes.
  • spec searched: rg -il 'ttlMs|tasks/get|Aufgabe' docs/specs/ → 0028 §10a covers this area
  • verdict: the spec change is present and matches the code (§10a ttl and lazy expiry, Completed decision, §10 test cases). The changelog fragment is present, in English, with the version and CHANGELOG.md unchanged.

Security checks

  • The owner check (owner.session.client != caller.session.client) is unchanged. The expiry check only adds a not-found path before it, so it is narrower and not a loosening.
  • Loosening check against origin/develop for extension.rs: no condition removed. Every new path returns not-found or drops an entry. Without the extension being asked, no path grants access.
  • Bypass attempts:
    • a foreign client probing an expired id
    • ttl 0
    • a huge ttl
    • re-using an id after expiry
    • a duplicate live id
      None of these reaches another client's task or skips the confirmation. The task path never touches FilterEngine or the confirmation flow.
  • Threat model: no change – only forgets task ids earlier; owner check unchanged: reason holds, CI threat-model-note green.

Manual checks pending

None.

Follow-ups

None.

@smart-ssh-coordinator
smart-ssh-coordinator Bot merged commit 4801750 into develop Dec 4, 2026
10 checks passed
@smart-ssh-coordinator
smart-ssh-coordinator Bot deleted the issue-1660-mcp-tasks-honour-ttl-test-not-found branch December 4, 2026 10:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MCP tasks: honour ttl, test not-found after session close, spec the Completed decision

0 participants